package com.li.test.model3;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 - 消费者
 */
@RestController
@RequestMapping("/consumer")
@Slf4j
public class ConsumerController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/simpleQueue")
    public ResponseEntity simpleQueue() {
        // 接收消息
        String message = (String) rabbitTemplate.receiveAndConvert("simple.queue");
        // 输出消息
        log.info("消费者接收到的消息: {}", message);
        return ResponseEntity.ok("消费者消费消息成功：" + message);
    }
}